package com.林子祺.全名健康管理系统.view.servlet.login;

import com.林子祺.全名健康管理系统.controller.loginandregister.Collection;
import com.林子祺.全名健康管理系统.entity.article.content.comment.CommentData;
import com.林子祺.全名健康管理系统.entity.article.content.comment.CurrentCommentData;
import com.林子祺.全名健康管理系统.entity.login.CollectionData;
import com.林子祺.全名健康管理系统.entity.login.CurrentCollectionData;
import com.林子祺.全名健康管理系统.util.CollectionStructure;
import com.林子祺.全名健康管理系统.util.CommentStructure;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

//显示收藏
@WebServlet("/CollectionData")
public class CollectionIndexDisplay extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String user = req.getParameter("user");
        System.out.println(user);

        CollectionData.Refresh();
        Collection.pull(user);

        int number = 0;
        ArrayList<CollectionStructure> collection = new ArrayList<>();
        while(CollectionData.OutputCollectionData(number)){
            System.out.println(CurrentCollectionData.user);
            collection.add(new CollectionStructure(CurrentCollectionData.user, CurrentCollectionData.collection));
            number++;
        }

        req.setAttribute("Collection",collection);
        req.getRequestDispatcher("/content/collection.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
